//
//  ZWWelcomeViewController.swift
//  ZWWeibo
//
//  Created by flyiron on 16/4/19.
//  Copyright © 2016年 flyiron. All rights reserved.
//

import UIKit
import SDWebImage

class ZWWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
//         更新约束
        headImage.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(view.snp_top).offset(150)
        }
        UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        NSNotificationCenter.defaultCenter().postNotificationName("changeRootVC", object: self)
                })
        }
        
    }
    func setupUI(){
         view.backgroundColor = UIColor(white: 247/255.0, alpha: 1)
        view.addSubview(messageLabel)
        view.addSubview(headImage)
        
        headImage.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 80, height: 80))
            make.centerX.equalTo(view)
            make.top.equalTo(200)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            make.top.equalTo(headImage.snp_bottom).offset(15)
        }
        
        
    }
    
    
    lazy var headImage: UIImageView = {
    var view = UIImageView(image: UIImage(named: "avatar_default_big"))
    let viewModel = ZWUserInfoViewModel.sharedViewModel
        if let image = viewModel.userModel?.avatar_large {
            let imageurl = NSURL(string: image)
            view .sd_setImageWithURL(imageurl, placeholderImage: UIImage(named: "avatar_default_big"))
        }
        view.layer.cornerRadius = 40
        view.layer.masksToBounds = true

    return view
    }()
    
    lazy var messageLabel: UILabel = {
    var label = UILabel()
        label.text = "欢迎回来"
        label.textColor = UIColor.grayColor()
        label.font = UIFont.systemFontOfSize(15)
        label.alpha = 0
    return label
    }()
    
    
    
  

}
